public class Test {
    public static void main(String[] args) {
        int[] arr = {1,8,6,2,5,4,8,3,7};
        int ret = maxArea(arr);
        System.out.println(ret);
    }

    public static int maxArea(int[] height) {
        int max = 0, left = 0, right = height.length-1;
        while(left != right){
           int area = Math.min(height[left], height[right]) * (right - left);
           max = Math.max(max,area);
           if(height[left] < height[right]){
               left++;
           }else{
               right--;
           }
        }
        return max;
    }
}
